home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 January / PCWorld_2007-01_cd.bin / v cisle / hotkey / AutoHotkey104504_Install.exe / Extras / Generate jEdit.ahk < prev    next >
Text File  |  2005-03-27  |  6KB  |  194 lines

  1. ;___________________________________________
  2.  
  3. ;     TextPad Syntax Generator Script
  4. ;               -19.03.2005 A. Gleichmann
  5. ;        the syntaxfile must be addes to the jedit catalog file:
  6. ;        <MODE NAME="ahk" FILE="ahk.xml" FILE_NAME_GLOB="*.{ahk}"/>
  7. ;               -26.03.2005 A. Gleichmann 
  8. ;          change the writung from the first part of the xml file for better reading
  9. ;___________________________________________
  10.  
  11. SetBatchLines, -1     ; Speeds up file operations.
  12. SetWorkingDir, ..\..  ; Set it to the Editors folder.
  13.  
  14. TargetFile = jEdit\ahk.xml
  15. FileDelete, %TargetFile%
  16. ;little tricky for performance reason
  17. ;do an loop, read for performance reason as the output file is not closed an open for each line
  18. Loop, Read, %A_ScriptDir%\%A_ScriptName%, %TargetFile%
  19. {
  20.     FileAppend, <?xml version="1.0"?>`n
  21.     FileAppend, `n
  22.     FileAppend, <!DOCTYPE MODE SYSTEM "xmode.dtd">`n
  23.     FileAppend, `n
  24.     FileAppend, <!--`n
  25.     FileAppend, `t19.03.2005 - A. Gleichmann`n
  26.     FileAppend, `tAdded the AutoHotkeys Command`n
  27.     FileAppend, `tthis file is based on the  JEdit batch.xml mode.`n
  28.     FileAppend, -->`n
  29.     FileAppend, `n
  30.     FileAppend, <!-- The keywords and functions here defined are those of AutoHotkey Programm`n
  31.     FileAppend,    JEdit keyword syntax file for AutoHotkey`n
  32.     FileAppend,    Auto generated by A. Gleichmanns JEdit Syntax Generator Script`n`n
  33.     FileAppend,  -->`n
  34.     
  35.     FileAppend, <MODE>`n
  36.     FileAppend, `t<PROPS>`n
  37.     FileAppend, `t`t<PROPERTY NAME="lineComment" VALUE=";" />`n
  38.     FileAppend, `t`t<PROPERTY NAME="wordBreakChars" VALUE="`,+-=<>/?^&*" />`n
  39.     FileAppend, `t`t<PROPERTY NAME="indentOpenBrackets" VALUE="{" />`n
  40.     FileAppend, `t`t<PROPERTY NAME="indentCloseBrackets" VALUE="}" />`n
  41.     FileAppend, `t`t<PROPERTY NAME="doubleBracketIndent" VALUE="false" />`n
  42.     FileAppend, `t`t<PROPERTY NAME="lineUpClosingBracket" VALUE="true" />`n
  43.     FileAppend, `t</PROPS>`n
  44.     FileAppend, `t<RULES ESCAPE="``" IGNORE_CASE="TRUE" HIGHLIGHT_DIGITS="TRUE" DIGIT_RE="(0x[[:xdigit:]]+[lL]?|[[:digit:]]+(e[[:digit:]]*)?[lLdDfF]?)">`n
  45.     FileAppend, `t`t<EOL_SPAN TYPE="COMMENT1">;</EOL_SPAN>`n
  46.     FileAppend, `t`t<!-- Comparison operators -->`n
  47.     FileAppend, `t`t<SEQ TYPE="OPERATOR"><</SEQ>`n
  48.     FileAppend, `t`t<SEQ TYPE="OPERATOR"><=</SEQ>`n
  49.     FileAppend, `t`t<SEQ TYPE="OPERATOR">>=</SEQ>`n
  50.     FileAppend, `t`t<SEQ TYPE="OPERATOR">></SEQ>`n
  51.     FileAppend, `t`t<SEQ TYPE="OPERATOR">=</SEQ>`n
  52.     FileAppend, `t`t<SEQ TYPE="OPERATOR"><></SEQ>`n
  53.     FileAppend, `t`t<!-- Arithmetic operators -->`n
  54.     FileAppend, `t`t<SEQ TYPE="OPERATOR">+</SEQ>`n
  55.     FileAppend, `t`t<SEQ TYPE="OPERATOR">-</SEQ>`n
  56.     FileAppend, `t`t<SEQ TYPE="OPERATOR">*</SEQ>`n
  57.     FileAppend, `t`t<SEQ TYPE="OPERATOR">/</SEQ>`n
  58.     FileAppend, `t`t<SEQ TYPE="OPERATOR">\</SEQ>`n
  59.     FileAppend, `t`t<SEQ TYPE="OPERATOR">:=</SEQ>`n
  60.     FileAppend, `t`t<MARK_PREVIOUS AT_WHITESPACE_END="TRUE" EXCLUDE_MATCH="TRUE" TYPE="LABEL">:</MARK_PREVIOUS>`n
  61.     FileAppend, `t`t<MARK_PREVIOUS AT_WHITESPACE_END="TRUE" EXCLUDE_MATCH="TRUE" TYPE="LABEL">`::</MARK_PREVIOUS>`n
  62.     FileAppend, `n`n
  63.     FileAppend,`t`t<KEYWORDS>`n
  64.     break
  65. }
  66.  
  67.  
  68. ;this doesn't require fancy cmd names for human reading,
  69. ;it just requires names to be highlighted. so getting first name only
  70.  
  71. Loop, Read, Syntax\CommandNames.txt, %TargetFile%
  72. {
  73.     checkLine=%a_loopreadline%
  74.     gosub, checkComment
  75.     IfEqual, rc, 0
  76.          FileAppend, `t`t`t<!-- %CurrCmd%  -->`n
  77.     else {
  78.         CurrCmd =
  79.         FullCmd = %a_loopreadline%
  80.         
  81.         ;directives don't have first comma but a first space
  82.         ;so whichever is first, take it as end of cmd name
  83.         StringGetPos, cPos, FullCmd, `,
  84.         StringGetPos, sPos, FullCmd, %A_Space%
  85.         
  86.         IfLess, sPos, %cPos%
  87.             IfGreater, sPos, 0
  88.                 StringLeft, CurrCmd, FullCmd, %sPos%
  89.         IfLess, cPos, %sPos%
  90.             IfGreater, cPos, 0
  91.                 StringLeft, CurrCmd, FullCmd, %cPos%
  92.         IfLess, cPos, %sPos%
  93.             IfLess, cPos, 0
  94.                 StringLeft, CurrCmd, FullCmd, %sPos%
  95.         IfLess, sPos, %cPos%
  96.             IfLess, sPos, 0
  97.                 StringLeft, CurrCmd, FullCmd, %cPos%
  98.  
  99.         StringReplace, FullCmd, FullCmd, ``n, `n, a
  100.         StringReplace, FullCmd, FullCmd, ``t, `t, a
  101.     
  102.         StringReplace, CurrCmd, CurrCmd, [,, a
  103.         StringReplace, CurrCmd, CurrCmd, %a_space%,, a
  104.         
  105.         ;For a directive that has no parameters
  106.         IfEqual, CurrCmd,
  107.             CurrCmd = %FullCmd%
  108.     
  109.         ;this check removes duplicates for loop and if
  110.         IfNotEqual, CurrCmd,
  111.             IfNotEqual, CurrCmd, %LastCmd%
  112.                 FileAppend, `t`t`t<KEYWORD1>%CurrCmd%</KEYWORD1>`n
  113.     }    
  114.     LastCmd = %CurrCmd%
  115. }
  116.  
  117. FileAppend, `n`n, %TargetFile%
  118. Loop, Read, Syntax\Keywords.txt, %TargetFile%
  119. {
  120.     CurrCmd = %a_loopreadline%
  121.  
  122.     checkLine=%CurrCmd%
  123.     gosub, checkComment
  124.     IfEqual, rc, 0
  125.         FileAppend, `t`t`t<!-- %CurrCmd%  -->`n
  126.     else {
  127.         ;this check removes duplicates for loop and if
  128.         IfNotEqual, CurrCmd,
  129.             IfNotEqual, CurrCmd, %LastCmd%
  130.                 FileAppend, `t`t`t<KEYWORD2>%CurrCmd%</KEYWORD2>`n
  131.     }
  132.     
  133.     LastCmd = %CurrCmd%
  134. }
  135. FileAppend, `n`n, %TargetFile%
  136. Loop, Read, Syntax\Variables.txt, %TargetFile%
  137. {
  138.     CurrCmd = %a_loopreadline%
  139.  
  140.     checkLine=%CurrCmd%
  141.     gosub, checkComment
  142.     IfEqual, rc, 0
  143.         FileAppend, `t`t`t<!-- %CurrCmd%  -->`n
  144.     else {
  145.         ;this check removes duplicates for loop and if
  146.         IfNotEqual, CurrCmd,
  147.             IfNotEqual, CurrCmd, %LastCmd%
  148.                 FileAppend, `t`t`t<KEYWORD3>%CurrCmd%</KEYWORD3>`n
  149.     }
  150.     
  151.     LastCmd = %CurrCmd%
  152. }
  153. FileAppend, `n`n, %TargetFile%
  154. Loop, Read, Syntax\Keys.txt, %TargetFile%
  155. {
  156.     CurrCmd = %a_loopreadline%
  157.  
  158.     checkLine=%CurrCmd%
  159.     gosub, checkComment
  160.     IfEqual, rc, 0
  161.         FileAppend, `t`t`t<!-- %CurrCmd%  -->`n
  162.     else {
  163.         ;this check removes duplicates for loop and if
  164.         ;keys are added with and without {}
  165.         IfNotEqual, CurrCmd,
  166.             IfNotEqual, CurrCmd, %LastCmd% 
  167.             {
  168.                 FileAppend, `t`t`t<LITERAL2>%CurrCmd%</LITERAL2>`n
  169.                 FileAppend, `t`t`t<LITERAL2>{%CurrCmd%}</LITERAL2>`n
  170.             }
  171.     }
  172.     
  173.     LastCmd = %CurrCmd%
  174. }
  175. FileAppend, `n`t`t</KEYWORDS>`n, %TargetFile%
  176.  
  177.  
  178. FileAppend, `t</RULES>`n, %TargetFile%
  179. FileAppend, </MODE>`n, %TargetFile%
  180.  
  181. return
  182.  
  183. checkComment:
  184.     ;comment check
  185.     StringReplace, check, checkLine , %A_Space%,, A
  186.     StringReplace, check, check, %A_Tab%,, A
  187.     StringLeft, check, check, 1
  188.     IfEqual, check, `;
  189.         rc=0
  190.     else
  191.         rc=1
  192.     return
  193.  
  194.